package com.lu.stack.api.controller;

import com.alibaba.fastjson.JSON;
import com.lu.stack.common.model.response.R;
import com.lu.stack.nacos.feign.FeignArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zhanglu
 * @project lu-cloud-stack
 * @description
 * @date 2023/2/1 23:38
 */
@Slf4j
@RequestMapping("/test")
@RestController
public class TestController {

    @Resource
    private FeignArticleService feignArticleService;
    @Resource
    private Environment environment;

    @GetMapping("/t2")
    public Object t2(){
        log.info("feignArticleService.t2 start");
        Object o = feignArticleService.t2();
        log.info("feignArticleService.t2 end");
        return o;
    }

    @PostMapping("/t3")
    public Object t3(@RequestBody Map<String, Object> params){
        log.info("feignArticleService.t3 params:{}", JSON.toJSONString(params));
        return 1;
    }

    @GetMapping("/t4")
    public R t4(){
        return R.success(environment.getProperty("spring.application.name") + environment.getProperty("server.port"));
    }

    @GetMapping("/t5")
    public R t5(){
        return feignArticleService.t5();
    }

}
